<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>检测对象类型</title>
</head>

<body>
    <p></p>
    <script>
        // Object.prototype.toString
        console.log(Object.prototype.toString.call(1)) // "[object Number]"
        console.log(Object.prototype.toString.call('hi')) // "[object String]"
        console.log('hi'.toString()); // 'hi'
        console.log(Object.prototype.toString.call({ a: 'hi' })) // "[object Object]"
        console.log({ a: 'hi' }.toString()); // "[object,object]"
        console.log(Object.prototype.toString.call([1, 'a'])) // "[object Array]"
        console.log([1, 'a'].toString()); // "1,a"
        console.log(Object.prototype.toString.call(true)) // "[object Boolean]"
        console.log(true.toString()); // "true"
        console.log(Object.prototype.toString.call(() => { })) // "[object Function]"
        console.log(((a) => { 2 }).toString()); // "(a) => { 2 }"
        console.log(Object.prototype.toString.call(null)) // "[object Null]"
        // console.log(null.toString()); // 没有toString()方法
        console.log(Object.prototype.toString.call(undefined)) // "[object Undefined]"
        // console.log(undefined.toString()); // 没有toString()方法
        console.log(Object.prototype.toString.call(Symbol(1))) // "[object Symbol]"
        console.log(Symbol(1).toString()); // "Symbol(1)"
    </script>
</body>

</html>